package psnl.bingo.mr.demo4;

import org.apache.hadoop.mapreduce.InputSplit;
import org.apache.hadoop.mapreduce.JobContext;
import org.apache.hadoop.mapreduce.lib.input.FileSplit;
import org.apache.hadoop.mapreduce.lib.input.TextInputFormat;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class D4InputFormat extends TextInputFormat {
    @Override
    public List<InputSplit> getSplits(JobContext job) throws IOException {
        List<InputSplit> splits = super.getSplits(job);
        List<InputSplit> realSplits = new ArrayList<>();

        for (InputSplit s : splits) {
            FileSplit fileSplit = (FileSplit) s;
            String fileName = fileSplit.getPath().getName();
            if(fileName.startsWith("ab")) {
                realSplits.add(s);
            }
        }

        return realSplits;
    }
}
